package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcRfidEventMapper;
import com.csun.cmny.provider.model.domain.DmcRfidEvent;
import com.csun.cmny.provider.model.dto.rfid.RfidEventPageQuery;
import com.csun.cmny.provider.model.vo.rfid.DmcRfidLabelVo;
import com.csun.cmny.provider.model.vo.rfid.DmcRfidReaderVo;
import com.csun.cmny.provider.service.DmcRfidEventService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-01-22 14:55
 * @Description: the class dmc rfid event service impl
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class DmcRfidEventServiceImpl extends BaseService<DmcRfidEvent> implements DmcRfidEventService {

    @Resource
    private DmcRfidEventMapper dmcRfidEventMapper;

    /**
     * save dmc rfid event
     *
     * @param dmcRfidEvent dmc rfid event
     * @return the int
     */
    @Override
    public Integer saveDmcRfidEvent(DmcRfidEvent dmcRfidEvent) {

        return mapper.insertSelective(dmcRfidEvent);
    }

    /**
     * query dmc rfid event list with page
     *
     * @param rfidEventPageQuery    rfid event page query
     *
     * @return  the page info
     */
    @Override
    public List<DmcRfidEvent> queryDmcRfidEventListWithPage(RfidEventPageQuery rfidEventPageQuery) {

        return dmcRfidEventMapper.queryDmcRfidEventListWithPage(rfidEventPageQuery);
    }

    /**
     * select one times rfid event by label no
     *
     * @param labelNo the label no
     *
     * @return the dmc rfid event
     */
    @Override
    public DmcRfidEvent selectOneByLabelNo(String labelNo) {

        return dmcRfidEventMapper.selectOneByLabelNo(labelNo);
    }

    /**
     * save dmc rfid event
     *
     * @param dmcRfidReaderVo dmc rfid reader vo
     * @param dmcRfidLabelVo  dmc rfid label vo
     *
     * @return the int.
     */
    @Override
    public Integer saveDmcRfidEvent(DmcRfidReaderVo dmcRfidReaderVo, DmcRfidLabelVo dmcRfidLabelVo) {

        DmcRfidEvent dmcRfidEvent = new DmcRfidEvent();
        dmcRfidEvent.setGroupId(dmcRfidLabelVo.getGroupId());
        dmcRfidEvent.setLabelId(dmcRfidLabelVo.getId());
        dmcRfidEvent.setLabelNo(dmcRfidLabelVo.getDeviceNo());
        dmcRfidEvent.setReaderId(dmcRfidReaderVo.getId());
        dmcRfidEvent.setReaderNo(dmcRfidReaderVo.getDeviceNo());

        return dmcRfidEventMapper.insertSelective(dmcRfidEvent);
    }

    /*
     *出入记录查询
     * */
    @Override
    public List<DmcRfidEvent> queryDmcRfidEventListWithPageByRoleName(RfidEventPageQuery rfidEventPageQuery) {
        return dmcRfidEventMapper.queryDmcRfidEventListWithPageByRoleName(rfidEventPageQuery);
    }
}
